package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.sevice.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 分页查询订单
     * @param queryPageBean
     * @return
     */
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = orderService.findPage(queryPageBean);

        return pageResult;
    }

    /**
     * 修改状态
     * @param order
     * @return
     */
    @PostMapping("/update")
    public Result updateOrderStatus(@RequestBody Order order){
        Integer recordCount = orderService.updateOrderStatus(order);

        return new Result(true, MessageConstant.ORDERSETTING_SUCCESS, recordCount);
    }
}
